//
//  ChangeClassViewController.m
//  Learn
//
//  Created by zyl_macbookpro on 2024/4/1.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "ChangeClassViewController.h"
#import "MineAPIManager.h"

@interface ChangeClassViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic ,strong)UITableView *tableView;

@property(nonatomic ,strong)UITextField *userNameTextFiled;

@property(nonatomic ,strong)UIView *tableFootorView;

@end

@implementation ChangeClassViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self renderNavBarWithBackgroundImage:[UIImage imageWithColor:lWhiteColor] backgroundColor:lClearColor shadowColor:nil textAttributeDic:@{NSForegroundColorAttributeName:rgba(51, 51, 51, 1),NSFontAttributeName:MFontWithSize(18)} enableScrollEdgeAppearance:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"更换班级";
    // Do any additional setup after loading the view.
    [self setBackButtonIsHidden:NO];
    [self.view addSubview:self.tableView];
    self.view.backgroundColor = rgba(245, 245, 245, 1);
}
- (void)confirmBtnAction
{
    [self.view endEditing:YES];
    if (self.userNameTextFiled.text.length == 0) {
        return;
    }
    [MineAPIManager ChangeClassWithParam:@{@"class_id":self.userNameTextFiled.text} result:^(NSDictionary * _Nonnull dic) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }];
}
#pragma mark -UITableViewDelegate,UITableViewDelegate
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
    }
    [cell removeAllSubviews];
    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, lScreenWidth - 50, 22)];
    titleLabel.font = MFontWithSize(16);
    titleLabel.text = @"请输入老师给的号码更换班级";
    [titleLabel setTextAlignment:NSTextAlignmentLeft];
    titleLabel.textColor = rgba(51, 51, 51, 1);
    
    
    [cell addSubview:titleLabel];
    [cell.contentView addSubview:self.userNameTextFiled];
  
    return cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 79;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    
}
#pragma mark -getters and setters
-(UITableView *)tableView{
    if (!_tableView){
        _tableView =[[UITableView alloc] initWithFrame:CGRectMake(0, lTopBarHeight, lScreenWidth, lScreenHeight - lTopBarHeight) style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        _tableView.bounces = NO;
        [_tableView setBackgroundColor:lClearColor];
        [_tableView setSeparatorColor:rgba(229, 229, 229, 1)];
        [_tableView setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 0)];
        [_tableView setTableFooterView:self.tableFootorView];
    }
    
    return _tableView;
}
-(UIView *)tableFootorView
{
    if (!_tableFootorView)
    {
        _tableFootorView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, lScreenWidth, 146)];
        _tableFootorView.backgroundColor = lClearColor;
        UIButton *confirmBtn = [UIButton new];
        confirmBtn.frame =CGRectMake(0, 0, lScreenWidth - 20, 45);
       
        confirmBtn.selected =NO;
        [confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
        [confirmBtn setTitleColor:lWhiteColor forState:UIControlStateNormal];
        [confirmBtn.titleLabel setFont:MFontWithSize(18)];
        [confirmBtn addTarget:self action:@selector(confirmBtnAction) forControlEvents:UIControlEventTouchUpInside];
        confirmBtn.backgroundColor = lClearColor;
        UIView *btnView =[[UIView alloc] initWithFrame:CGRectMake((lScreenWidth - confirmBtn.width)/2.0, 60, confirmBtn.width, confirmBtn.height)];
        [btnView setAllCornersWithCornerRadius:confirmBtn.height/2.0];
        // gradient
        CAGradientLayer *gl = [CAGradientLayer layer];
        gl.frame = CGRectMake(0,0,btnView.width,btnView.height);
        gl.startPoint = CGPointMake(1, 0.5);
        gl.endPoint = CGPointMake(0, 0.5);
        gl.colors = @[(__bridge id)[UIColor colorWithRed:41/255.0 green:241/255.0 blue:156/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:2/255.0 green:161/255.0 blue:249/255.0 alpha:1.0].CGColor];
        gl.locations = @[@(0), @(1.0f)];
        [btnView.layer addSublayer:gl];
        [btnView addSubview:confirmBtn];
        [_tableFootorView addSubview:btnView];
        [_tableFootorView setHeight:btnView.bottom];
    }
    
    return _tableFootorView;
    
}
-(UITextField *)userNameTextFiled
{
    if (!_userNameTextFiled)
    {
        _userNameTextFiled =[[UITextField alloc] initWithFrame:CGRectMake(10, 32, lScreenWidth - 20, 47)];
        _userNameTextFiled.font = MFontWithSize(16);
        _userNameTextFiled.textColor = rgba(51, 51, 51, 1);
        _userNameTextFiled.clearButtonMode =UITextFieldViewModeWhileEditing;
        _userNameTextFiled.attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:@"请输入" attributes:@{NSFontAttributeName:MFontWithSize(16)}];
       
        if (@available(iOS 11.0,*)) {
            _userNameTextFiled.textContentType =UITextContentTypeUsername;
        }
       

    }

    return _userNameTextFiled;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
